﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.CommandWpf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.UI.WebControls;
using System.Windows;

namespace Jn698._45GWTool.ViewModels
{
    public class ProxyTransmitCommViewModel:ViewModelBase
    {
        public static string commControl;
        private IList<string> baudrateList;
        public IList<string> BaudrateList
        {
            get => baudrateList;
            set => Set(ref baudrateList, value);
        }

        private int baudrateIndex;

        public int BaudrateIndex
        {
            get { return baudrateIndex; }
            set { Set(ref baudrateIndex,value); }
        }

        private IList<string> parityList;
        public IList<string> ParityList
        {
            get => parityList;
            set => Set(ref parityList, value);
        }

        private int parityIndex;

        public int ParityIndex
        {
            get { return parityIndex; }
            set { Set(ref parityIndex, value); }
        }

        private IList<string> dataList;
        public IList<string> DataList
        {
            get => dataList;
            set => Set(ref dataList, value);
        }

        private int dataIndex;

        public int DataIndex
        {
            get { return dataIndex; }
            set { Set(ref dataIndex, value); }
        }

        private IList<string> stopList;
        public IList<string> StopList
        {
            get => stopList;
            set => Set(ref stopList, value);
        }

        private int stopIndex;

        public int StopIndex
        {
            get { return stopIndex; }
            set { Set(ref stopIndex, value); }
        }

        private IList<string> controlList;
        public IList<string> ControlList
        {
            get => controlList;
            set => Set(ref controlList, value);
        }

        private int controlIndex;

        public int ControlIndex
        {
            get { return controlIndex; }
            set { Set(ref controlIndex, value); }
        }

        public ProxyTransmitCommViewModel()
        {

            BaudrateList = new List<string>() { "300","600","1200","2400","4800","7200","9600","19200","38400","57600","115200"};
            ParityList = new List<string>() { "无校验","奇校验","偶校验"};
            DataList = new List<string>() { "5","6","7","8"};
            StopList = new List<string>() { "1","2"};
            ControlList = new List<string>() { "无","硬件","软件"};
        }

        public RelayCommand<Window> OKCommand 
        {
            get
            {
                var command = new RelayCommand<Window>((w) => 
                {
                    commControl = string.Format("{0},{1},{2},{3},{4}", BaudrateIndex, ParityIndex, DataIndex, StopIndex, ControlIndex);
                    w.DialogResult = true;
                });
                return command;
            }
        }

        public RelayCommand<Window> CancelCommand
        {
            get
            {
                var command = new RelayCommand<Window>((w) =>
                {
                    w.DialogResult = false;
                });
                return command;
            }
        }
    }
}
